<template>
	<view class="webview-page">
		<web-view :src="webUrl"></web-view>
	</view>
</template>

<script>
import { mapState } from 'vuex'
import queryString from 'query-string'

export default {
	computed: {
		...mapState({
			pid: state => state.pid,
			platform: state => state.platform,
			userInfo: state => state.user.userInfo
		})
	},
	data () {
		return {
			webUrl: ''
		}
	},
	onLoad (options) {
		let url = decodeURIComponent(options.webUrl)
		const needQuery = options.needQuery || '1'
		const hsbParams = {
			pid: this.pid,
			platform: this.platform
		}
		if (this.userInfo.token) {
			hsbParams.token = this.userInfo.token
		}
		if (needQuery === '1') {
			if (url.indexOf('?') !== -1) {
				url += `&${queryString.stringify(hsbParams)}`
			} else {
				url += `?${queryString.stringify(hsbParams)}`
			}
		}
		this.webUrl = url
	}
}
</script>
